<?php
namespace Tool\Controller;
use Common\Controller\AdminbaseController;
use Home\Service\AccountService;
use Home\Service\ClockTimeService;

// +----------------------------------------------------------------------
// | Date:2017年3月6日
// +----------------------------------------------------------------------
// | Author: EK_熊<1439527494@qq.com>
// +----------------------------------------------------------------------
// | Description: 此文件作用于****
// +----------------------------------------------------------------------
class IndexController extends AdminbaseController{
    public function login(){
        $dep_id = I('dep_id');
        $name = I('name');
        if ($name)  $account_map['ep_name'] = ['like',"%$name%"];

        $account_map['wx_openid'] = ['neq',''];
        $account_map['status'] = 1;
        if ($dep_id) $account_map['department_id']=$dep_id;
        $accountService = new AccountService();
        $list = $accountService->get_all_user_baseinfo("ep_name,REPLACE(email,'@gdinsight.com','') as account,password",$account_map);
        $this->assign('list',$list);

        $this->display();
    }
    
    //登陆跳转操作
    public function doLogin(){
        session('user',null);
        cookie('user',null);
        $account=I('account');
        $pwd=I('pwd');
        $accountService = new AccountService();
        $ret = $accountService->login($account,$pwd,'sn,position_lvl_id,leader_id,dep_id,dep_name,join_date,wx_openid,is_attendance,privilege',false,true);
        if (!$ret) $this->error($accountService->getError());
        $userinfo = $accountService->userInfo();
        /*添加年假记录*/
        $remianDays = D('AnnualLeave')->update_login($userinfo['sn'],$userinfo['join_date']);
        $this->redirect(U('Home/index/index'));

    }


    public function calculate(){
        $start = I('start_time');
        $end = I('end_time');

        $clockService = new ClockTimeService($start,$end);
        $attendanceInfo = $clockService->attendance_info();
        $this->assign('info',$attendanceInfo);

        $this->display();
    }
    
}